package me.algo;

import com.google.common.collect.Lists;
import com.google.common.hash.HashCode;

import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @author guozheng
 * @date 2024/4/11
 */
public class A1 {


    public static void main(String[] args) {

        int[] ints = {-1, 0, 1, 2, -1, -4};

        HashSet<List<Integer>> lists = new HashSet<>();
        lists.add(Lists.newArrayList(1, 2, 3));
        lists.add(Lists.newArrayList(2, 1, 3));
        int[] a = {3,-2,1,0};
        List<List<Integer>> lists1 = threeSum(a);
        System.out.println(lists1);

    }


    public static List<List<Integer>> threeSum(int[] nums) {
        if (nums.length < 3) {
            return new ArrayList<>();
        }

        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
        }
        Set<List<Integer>> rtn = new HashSet<>();
        for (int i = 0; i < nums.length-2; i++) {
            for (int k = i + 1; k < nums.length - 1; k++) {
                int a = nums[i];
                int b = nums[k];
                int z = 0 - a - b;
                if (map.containsKey(z)) {
                    Integer i1 = map.get(z);
                    if (i1 != i && i1 != k) {
                        ArrayList<Integer> one = new ArrayList<>();
                        one.add(a);
                        one.add(b);
                        one.add(z);
                        one.sort(Integer::compareTo);
                        rtn.add(one);
                    }
                }
            }
        }

        List<List<Integer>> lst = new ArrayList<>();
        lst.addAll(rtn);
        return lst;
    }


}
